package modelTest.model.mobsMovers;

import java.util.Iterator;
import java.util.Observable;

import modelTest.model.Coordinate;
import modelTest.model.GameStatus;
import modelTest.model.Moveable;
import modelTest.model.mobs.Mob;

public class LinearMover2D implements Runnable{
	
	private GameStatus status;
	
	public LinearMover2D( GameStatus status ) {
		this.status = status;
	}	
	
	@Override
	public synchronized void run() {
		
		String ID;
		boolean isKillable;
		
		while (true) {
			
//			mobIterator = status.getMobsIterator(true);
//			while (mobIterator.hasNext()) {
//				mobIterator.next().calculateNewCoordinate();;
//			}
			
			if (status.isRunning()) {
				Iterator<String> IDs = status.getMobsMapSet().iterator();
				while (IDs.hasNext()) {
					ID = IDs.next();
					Mob mob = status.getMob(ID);
					isKillable = mob.calculateNewCoordinate();
					if (isKillable) {
						status.killMob(ID);
					}
				}
			}
			
			try {
				Thread.sleep(10);								
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
